package com.boss.salary.controller;

import com.boss.api.dto.ApiResultDTO;
import com.boss.common.base.BasicinfoBaseController;
import com.boss.common.entity.PageDTO;
import com.boss.common.service.ICommonService;
import com.boss.common.util.PageUtils;
import com.boss.framework.dto.PaginationDTO;
import com.boss.framework.exception.AppRuntimeException;
import com.boss.salary.entity.OperrateLogs;
import com.boss.salary.entity.SalaryBankPayBack;
import com.boss.salary.service.IOperrateLogsService;
import com.boss.salary.service.ISalaryBankPayBackService;
import com.boss.sys.ca.user.dto.UserDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.MediaType;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/salaryBankPayBackController", produces = MediaType.APPLICATION_JSON)
public class SalaryBankPayBackController extends BasicinfoBaseController {

    /**
     * 引入日志框架常量
     */
    private final static Logger logger = LoggerFactory.getLogger(PersonSalaryInfoController.class);


    @Autowired
    private ISalaryBankPayBackService iSalaryBankPayBackService;

    @Autowired
    private ICommonService iCommonService;

    @Autowired
    private IOperrateLogsService iOperrateLogsService;

    /**
     * 查询 银行支付回盘表数据分页
     *
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/querySalaryBankPayBackPage")
    public ApiResultDTO querySalaryBankPayBackPage(@RequestHeader("X-Token") String tokenid,
                                                   @RequestParam(value = "page") String page,
                                                   @RequestParam(value = "limit") String limit,
                                                   @RequestParam(value = "flag") String flag,
                                                   @RequestParam(value = "agencyId") String agencyId,
                                                   @RequestParam(value = "salaCardBank") String salaCardBank,
                                                   @RequestParam(value = "idenNo") String idenNo) {
        try {
            UserDTO userDTO = getUser(tokenid);
            String province=userDTO.getProvince();
            Map<String, Object> queryParam = new HashMap<>(3);
            queryParam.put("province",province);
            queryParam.put("flag", flag);
            queryParam.put("salaCardBank", salaCardBank);
            queryParam.put("idenNo", idenNo);
            List<String> childrenId = iCommonService.getAgencyChildrenId(userDTO, agencyId);
            PaginationDTO paginationDTO = PageUtils.buildPaginationDTOPage(page, limit);
            PageDTO<SalaryBankPayBack> pageDTO = iSalaryBankPayBackService.querySalaryBankPayBackPage(paginationDTO, queryParam,childrenId);
            return ApiResultDTO.success(pageDTO, null);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "查询失败！");
        }
    }

    /**
     * 分发到单位
     *
     * @return
     */
    @PostMapping("/sendCardNoToAgency")
    public ApiResultDTO sendCardNoToAgency(@RequestHeader("X-Token") String tokenid,
                                           @RequestBody List<String> agencyIds) {
        try {
            UserDTO userDTO = getUser(tokenid);
            //添加操作日志
            OperrateLogs operrateLogs= new OperrateLogs();
            operrateLogs.setMofDivCode(userDTO.getProvince());
            operrateLogs.setTokenId(tokenid);
            operrateLogs.setUserAgencyId(userDTO.getAgency());
            operrateLogs.setUeserName(userDTO.getName());
            operrateLogs.setOperateName("异常卡号管理--异常卡号分发--分发到单位");
            iOperrateLogsService.saveOperrateLogs(operrateLogs);

            iSalaryBankPayBackService.sendCardNoToAgency(agencyIds);
            return ApiResultDTO.success(null, "分发成功");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "分发失败！");
        }
    }

    /**
     * 重新下发
     *
     * @param agencyIds
     * @return
     */
    @PostMapping("/cancelSendCard")
    public ApiResultDTO cancelSendCard(@RequestBody List<String> agencyIds) {
        try {
            String result = iSalaryBankPayBackService.cancelSendCard(agencyIds);
            return ApiResultDTO.success(result, "200".equals(result) ? "重新下发成功" : "存在财政已确认的单位，无法重新下发");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "操作失败！");
        }
    }

    /**
     * 查询 银行支付回盘表并且已下发的数据分页
     *
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/querySalaryBankPayBackSendPage")
    public ApiResultDTO querySalaryBankPayBackSendPage(@RequestHeader("X-Token") String tokenid,
                                                       @RequestParam(value = "page") String page,
                                                       @RequestParam(value = "limit") String limit,
                                                       @RequestParam(value = "flag") String flag,
                                                       @RequestParam(value = "agencyId") String agencyId,
                                                       @RequestParam(value = "idenNo") String idenNo) {
        try {
            String province=getUser(tokenid).getProvince();
            Map<String, Object> queryParam = new HashMap<>(3);
            queryParam.put("province",province);
            queryParam.put("flag", flag);
            queryParam.put("agencyId", agencyId);
            queryParam.put("idenNo", idenNo);
            PaginationDTO paginationDTO = PageUtils.buildPaginationDTOPage(page, limit);
            PageDTO<SalaryBankPayBack> pageDTO = iSalaryBankPayBackService.querySalaryBankPayBackSendPage(paginationDTO, queryParam);
            return ApiResultDTO.success(pageDTO, null);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "查询失败！");
        }
    }

    /**
     * 修改账户信息
     *
     * @param salaryBankPayBack
     * @return
     */
    @PostMapping("/updateBankInfo")
    public ApiResultDTO updateBankInfo(@RequestHeader("X-Token") String tokenid,
                                       @RequestBody SalaryBankPayBack salaryBankPayBack) {
        try {
            UserDTO userDTO = getUser(tokenid);
            //添加操作日志
            OperrateLogs operrateLogs= new OperrateLogs();
            operrateLogs.setMofDivCode(userDTO.getProvince());
            operrateLogs.setTokenId(tokenid);
            operrateLogs.setUserAgencyId(userDTO.getAgency());
            operrateLogs.setUeserName(userDTO.getName());
            operrateLogs.setOperateName("异常卡号管理--单位修改卡号--修改卡号");
            operrateLogs.setAgencyId(salaryBankPayBack.getAgencyId());
            iOperrateLogsService.saveOperrateLogs(operrateLogs);
            salaryBankPayBack.setMofDivCode(userDTO.getProvince());
            iSalaryBankPayBackService.updateBankInfo(salaryBankPayBack);
            return ApiResultDTO.success(null, "修改成功");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "修改失败！");
        }
    }

    /**
     * 撤销修改账户信息
     *
     * @param salaryBankPayBack
     * @return
     */
    @PostMapping("/revokeUpdate")
    public ApiResultDTO revokeUpdate(@RequestHeader("X-Token") String tokenid,
                                     @RequestBody List<SalaryBankPayBack> salaryBankPayBack) {
        try {
            UserDTO userDTO = getUser(tokenid);
            //添加操作日志
            OperrateLogs operrateLogs= new OperrateLogs();
            operrateLogs.setMofDivCode(userDTO.getProvince());
            operrateLogs.setTokenId(tokenid);
            operrateLogs.setUserAgencyId(userDTO.getAgency());
            operrateLogs.setUeserName(userDTO.getName());
            operrateLogs.setOperateName("异常卡号管理--单位修改卡号--撤销修改");

            iOperrateLogsService.saveOperrateLogs(operrateLogs);

            iSalaryBankPayBackService.revokeUpdate(salaryBankPayBack);
            return ApiResultDTO.success(null, "撤销修改成功");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "撤销修改失败！");
        }
    }

    /**
     * 审核通过
     *
     * @return
     */
    @PostMapping("/verifyPass")
    public ApiResultDTO verifyPass(@RequestHeader("X-Token") String tokenid,
                                   @RequestBody SalaryBankPayBack salaryBankPayBack) {
        try {
            UserDTO userDTO = getUser(tokenid);
            //添加操作日志
            OperrateLogs operrateLogs= new OperrateLogs();
            operrateLogs.setMofDivCode(userDTO.getProvince());
            operrateLogs.setTokenId(tokenid);
            operrateLogs.setUserAgencyId(userDTO.getAgency());
            operrateLogs.setUeserName(userDTO.getName());
            operrateLogs.setOperateName("异常卡号管理--单位修改卡号--审核通过");
            operrateLogs.setAgencyId(salaryBankPayBack.getAgencyId());
            iOperrateLogsService.saveOperrateLogs(operrateLogs);

            String result = iSalaryBankPayBackService.verifyPass(salaryBankPayBack);
            return ApiResultDTO.success(result, "500".equals(result) ? "审核不通过" : "审核通过");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "操作失败！");
        }
    }

    /**
     * 撤销审核
     *
     * @return
     */
    @PostMapping("/revokeVerify")
    public ApiResultDTO revokeVerify(@RequestBody SalaryBankPayBack salaryBankPayBack) {
        try {
            String result = iSalaryBankPayBackService.revokeVerify(salaryBankPayBack);
            return ApiResultDTO.success(result, "200".equals(result) ? "撤销审核成功" : "异常卡号已送审财政，不允许撤销操作");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "操作失败！");
        }
    }

    /**
     * 财政送审
     *
     * @return
     */
    @PostMapping("/sendVerifyFinance")
    public ApiResultDTO sendVerifyFinance(@RequestHeader("X-Token") String tokenid,
                                          @RequestBody SalaryBankPayBack salaryBankPayBack) {
        try {
            UserDTO userDTO = getUser(tokenid);
            //添加操作日志
            OperrateLogs operrateLogs= new OperrateLogs();
            operrateLogs.setMofDivCode(userDTO.getProvince());
            operrateLogs.setTokenId(tokenid);
            operrateLogs.setUserAgencyId(userDTO.getAgency());
            operrateLogs.setUeserName(userDTO.getName());
            operrateLogs.setOperateName("异常卡号管理--单位修改卡号--财政送审");
            operrateLogs.setAgencyId(salaryBankPayBack.getAgencyId());
            iOperrateLogsService.saveOperrateLogs(operrateLogs);

            String result = iSalaryBankPayBackService.sendVerifyFinance(salaryBankPayBack);
            return ApiResultDTO.success(result, "200".equals(result) ? "财政送审成功" : "单位未审核通过，不允许财政送审");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "操作失败！");
        }
    }

    /**
     * 撤销财政送审
     *
     * @return
     */
    @PostMapping("/revokeVerifyFinance")
    public ApiResultDTO revokeVerifyFinance(@RequestHeader("X-Token") String tokenid,
                                            @RequestBody SalaryBankPayBack salaryBankPayBack) {
        try {
            UserDTO userDTO = getUser(tokenid);
            //添加操作日志
            OperrateLogs operrateLogs= new OperrateLogs();
            operrateLogs.setMofDivCode(userDTO.getProvince());
            operrateLogs.setTokenId(tokenid);
            operrateLogs.setUserAgencyId(userDTO.getAgency());
            operrateLogs.setUeserName(userDTO.getName());
            operrateLogs.setOperateName("异常卡号管理--单位修改卡号--撤销财政送审");
            operrateLogs.setAgencyId(salaryBankPayBack.getAgencyId());
            iOperrateLogsService.saveOperrateLogs(operrateLogs);

            String result = iSalaryBankPayBackService.revokeVerifyFinance(salaryBankPayBack);
            return ApiResultDTO.success(result, "200".equals(result) ? "撤销财政送审成功" : "财政已操作或未送审财政");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "操作失败！");
        }
    }

    /**
     * 查询 财政审核卡号数据分页
     *
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/queryFinanceVerifyPage")
    public ApiResultDTO queryFinanceVerifyPage(@RequestHeader("X-Token") String tokenid,
                                               @RequestParam(value = "page") String page,
                                               @RequestParam(value = "limit") String limit,
                                               @RequestParam(value = "flag") String flag,
                                               @RequestParam(value = "agencyId") String agencyId,
                                               @RequestParam(value = "idenNo") String idenNo) {
        try {
            UserDTO userDTO = getUser(tokenid);
            String province=userDTO.getProvince();
            Map<String, Object> queryParam = new HashMap<>(3);
            queryParam.put("flag", flag);
            queryParam.put("agencyId", agencyId);
            queryParam.put("idenNo", idenNo);
            queryParam.put("province",province);
            List<String> childrenId = iCommonService.getAgencyChildrenId(userDTO, agencyId);
            PaginationDTO paginationDTO = PageUtils.buildPaginationDTOPage(page, limit);
            PageDTO<SalaryBankPayBack> pageDTO = iSalaryBankPayBackService.queryFinanceVerifyPage(paginationDTO, queryParam,childrenId);
            return ApiResultDTO.success(pageDTO, null);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "查询失败！");
        }
    }

    /**
     * 财政审核卡号 财政确认
     *
     * @param salaryBankPayBack
     * @return
     */
    @PostMapping("/financeVerifyConfirm")
    public ApiResultDTO financeVerifyConfirm(@RequestHeader("X-Token") String tokenid,
                                             @RequestBody List<SalaryBankPayBack> salaryBankPayBack) {
        try {
            UserDTO userDTO = getUser(tokenid);
            //添加操作日志
            OperrateLogs operrateLogs= new OperrateLogs();
            operrateLogs.setMofDivCode(userDTO.getProvince());
            operrateLogs.setTokenId(tokenid);
            operrateLogs.setUserAgencyId(userDTO.getAgency());
            operrateLogs.setUeserName(userDTO.getName());
            operrateLogs.setOperateName("异常卡号管理--财政接收卡号--财政确认");

            iOperrateLogsService.saveOperrateLogs(operrateLogs);

            String result = iSalaryBankPayBackService.financeVerifyConfirm(salaryBankPayBack);
            return ApiResultDTO.success(result, "200".equals(result) ? "财政确认成功" : "单位撤销送审  不能确认");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "操作失败！");
        }
    }

    /**
     * 财政审核卡号 财政退回
     *
     * @param salaryBankPayBack
     * @return
     */
    @PostMapping("/financeVerifySendBack")
    public ApiResultDTO financeVerifySendBack(@RequestHeader("X-Token") String tokenid,
                                              @RequestBody List<SalaryBankPayBack> salaryBankPayBack) {
        try {
            UserDTO userDTO = getUser(tokenid);
            //添加操作日志
            OperrateLogs operrateLogs= new OperrateLogs();
            operrateLogs.setMofDivCode(userDTO.getProvince());
            operrateLogs.setTokenId(tokenid);
            operrateLogs.setUserAgencyId(userDTO.getAgency());
            operrateLogs.setUeserName(userDTO.getName());
            operrateLogs.setOperateName("异常卡号管理--财政接收卡号--财政退回");

            iOperrateLogsService.saveOperrateLogs(operrateLogs);

            String result = iSalaryBankPayBackService.financeVerifySendBack(salaryBankPayBack);
            return ApiResultDTO.success(result, "200".equals(result) ? "财政退回成功" : "单位撤销送审  不能退回");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "操作失败！");
        }
    }

    /**
     * 财政审核卡号 取消确认
     *
     * @param salaryBankPayBack
     * @return
     */
    @PostMapping("/financeVerifyCancelConfirm")
    public ApiResultDTO financeVerifyCancelConfirm(@RequestBody List<SalaryBankPayBack> salaryBankPayBack) {
        try {
            String result = iSalaryBankPayBackService.financeVerifyCancelConfirm(salaryBankPayBack);
            return ApiResultDTO.success(result, "200".equals(result) ? "取消确认成功" : "取消确认失败");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "操作失败！");
        }
    }

    /**
     * 财政审核卡号 审核通过
     *
     * @param salaryBankPayBack
     * @return
     */
    @PostMapping("/financeVerifyAuditPass")
    public ApiResultDTO financeVerifyAuditPass(@RequestBody List<SalaryBankPayBack> salaryBankPayBack) {
        try {
            String result = iSalaryBankPayBackService.financeVerifyAuditPass(salaryBankPayBack);
            return ApiResultDTO.success(result, "200".equals(result) ? "审核通过成功" : "审核通过失败");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "操作失败！");
        }
    }

    /**
     * 财政审核卡号 撤回审核
     *
     * @param salaryBankPayBack
     * @return
     */
    @PostMapping("/financeVerifyUndoAudit")
    public ApiResultDTO financeVerifyUndoAudit(@RequestHeader("X-Token") String tokenid,
                                               @RequestBody List<SalaryBankPayBack> salaryBankPayBack) {
        try {
            UserDTO userDTO = getUser(tokenid);
            //添加操作日志
            OperrateLogs operrateLogs= new OperrateLogs();
            operrateLogs.setMofDivCode(userDTO.getProvince());
            operrateLogs.setTokenId(tokenid);
            operrateLogs.setUserAgencyId(userDTO.getAgency());
            operrateLogs.setUeserName(userDTO.getName());
            operrateLogs.setOperateName("异常卡号管理--财政接收卡号--撤销接收");

            iOperrateLogsService.saveOperrateLogs(operrateLogs);

            String result = iSalaryBankPayBackService.financeVerifyUndoAudit(salaryBankPayBack);
            return ApiResultDTO.success(result, "200".equals(result) ? "撤销审核成功" : "撤销审核失败");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "操作失败！");
        }
    }

    /**
     * 卡号财政处理 分页查询所有
     *
     * @return
     */
    @GetMapping("/queryCardNumberFiscalPage")
    public ApiResultDTO queryCardNumberFiscalPage(@RequestHeader("X-Token") String tokenid,
                                                  @RequestParam(value = "page") String page,
                                                  @RequestParam(value = "limit") String limit,
                                                  @RequestParam(value = "flag") String flag,
                                                  @RequestParam(value = "agencyId") String agencyId,
                                                  @RequestParam(value = "idenNo", required = false) String idenNo,
                                                  @RequestParam(value = "salaCardBank", required = false) String salaCardBank,
                                                  @RequestParam(value = "isLongUse", required = false) String isLongUse) {

        try {
            UserDTO userDTO = getUser(tokenid);
            String province = userDTO.getProvince();
            Map<String, Object> queryParam = new HashMap<>(6);
            queryParam.put("flag", flag);
            queryParam.put("agencyId", agencyId);
            queryParam.put("idenNo", idenNo);
            queryParam.put("salaCardBank", salaCardBank);
            queryParam.put("isLongUse", isLongUse);
            queryParam.put("mof_div_code",province);
            List<String> childrenId = iCommonService.getAgencyChildrenId(userDTO, agencyId);
            PaginationDTO paginationDTO = PageUtils.buildPaginationDTOPage(page, limit);
            PageDTO<SalaryBankPayBack> pageDTO = iSalaryBankPayBackService.queryCardNumberFiscalPage(paginationDTO, queryParam,childrenId);
            return ApiResultDTO.success(pageDTO, null);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "查询失败！");
        }
    }

    /**
     * 更新人员信息
     *
     * @return
     */
    @GetMapping("/updatePersonnelCardNumberFiscal")
    public ApiResultDTO updatePersonnelCardNumberFiscal() {
        try {
            iSalaryBankPayBackService.updatePersonnelCardNumberFiscal();
            return ApiResultDTO.success();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "更新人事信息失败！");
        }
    }

    /**
     * 撤销更新人员信息
     *
     * @return
     */
    @GetMapping("/undoUpdatePersonnelCardNumberFiscal")
    public ApiResultDTO undoUpdatePersonnelCardNumberFiscal() {
        try {
            iSalaryBankPayBackService.undoUpdatePersonnelCardNumberFiscal();
            return ApiResultDTO.success();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "撤销更新人事信息失败！");
        }
    }

    /**
     * 生成银行数据
     */
    @PostMapping("/generateBankData")
    public ApiResultDTO generateBankData(@RequestHeader("X-Token") String tokenId,
                                         @RequestBody List<String> agencyIds) {
        try {
            UserDTO userDTO = getUser(tokenId);
            //添加操作日志
            OperrateLogs operrateLogs= new OperrateLogs();
            operrateLogs.setMofDivCode(userDTO.getProvince());
            operrateLogs.setTokenId(tokenId);
            operrateLogs.setUserAgencyId(userDTO.getAgency());
            operrateLogs.setUeserName(userDTO.getName());
            operrateLogs.setOperateName("异常卡号管理--财政接收卡号--生成银行数据");

            iOperrateLogsService.saveOperrateLogs(operrateLogs);

            String province = getUser(tokenId).getProvince();
            iSalaryBankPayBackService.generateBankData(province,agencyIds);
            return ApiResultDTO.success("生成成功！");
        } catch (AppRuntimeException e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, e.getMessage());
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "生成失败！");
        }
    }

    /**
     * 重新生成银行数据
     */
    @PostMapping("/regenerateBankData")
    public ApiResultDTO regenerateBankData(@RequestHeader("X-Token") String tokenId,
                                           @RequestBody List<String> ids) {
        try {
            String province = getUser(tokenId).getProvince();
            iSalaryBankPayBackService.generateBankData(province,ids);
            return ApiResultDTO.success("重新生成成功！");
        } catch (AppRuntimeException e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, e.getMessage());
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "重新生成失败！");
        }
    }

    @GetMapping("/generateAndExportBankData")
    public ApiResultDTO generateAndExportBankData(@RequestHeader("X-Token") String tokenId, HttpServletResponse response){
        try {
            String province = getUser(tokenId).getProvince();
            String fileName = "银行数据.xls";
            fileName = new String(fileName.getBytes(), StandardCharsets.UTF_8);
            response.addHeader("Content-Disposition", "filename=" + fileName);
            OutputStream outputStream = response.getOutputStream();
            iSalaryBankPayBackService.generateAndExportBankData(province, outputStream);
            return ApiResultDTO.success("生成成功！");
        } catch (AppRuntimeException e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, e.getMessage());
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "生成失败！");
        }
    }

}
